package com.beetlestech.nfe.main.biz.com.impl;

import java.util.ArrayList;
import java.util.List;

import com.beetlestech.nfe.fw.core.biz.AbstractDBLogic;
import com.beetlestech.nfe.fw.core.util.StringUtil;
import com.beetlestech.nfe.main.biz.com.HbVExamList;
import com.beetlestech.nfe.main.biz.com.dto.VexaminfolistInfoDTO;
import com.beetlestech.nfe.main.biz.constant.CommonConstant;
import com.beetlestech.nfe.main.biz.constant.CtgCodeConstant;
import com.beetlestech.nfe.main.biz.constant.HbMessageCode;
import com.beetlestech.nfe.main.db.base.StatementDTO;
import com.beetlestech.nfe.main.db.base.StatementUtil;
import com.beetlestech.nfe.main.db.constant.SQLConstant;
import com.beetlestech.nfe.main.db.constant.SQLID;
import com.beetlestech.nfe.main.db.tbl.ExaminationdocDTO;
import com.beetlestech.nfe.main.db.tbl.MstusrDTO;
import com.beetlestech.nfe.main.db.tbl.UserjurisdictionDTO;
import com.beetlestech.nfe.main.db.view.VexaminfolistDTO;
public class HbVExamListImpl extends AbstractDBLogic implements HbVExamList, CtgCodeConstant, HbMessageCode, CommonConstant, SQLConstant {

	@Override
	public VexaminfolistInfoDTO[] getExamList(String examName,
			Integer typeCid) {
		List<VexaminfolistInfoDTO> examList = new ArrayList<VexaminfolistInfoDTO>();
		List<VexaminfolistDTO> examListDB = new ArrayList<VexaminfolistDTO>();
		VexaminfolistDTO vexaminfolistDTO =new VexaminfolistDTO();
		StatementDTO statementDTO = new StatementDTO();
		if(StringUtil.isNotEmpty(examName)){
			StatementUtil.andWhere(statementDTO, VexaminfolistDTO.COLUMN_NAME, StatementUtil.KEYWORD.LIKE ,examName);
		}
		if(typeCid!=0){
			StatementUtil.andWhere(statementDTO, VexaminfolistDTO.COLUMN_CATAGORY_C_ID, StatementUtil.KEYWORD.EQUAL ,typeCid);
//			StatementUtil.andWhere(statementDTO, VexaminfolistDTO.COLUMN_CATAGORY_P_ID, StatementUtil.KEYWORD.EQUAL ,CATAGORY_P_COURESE_TYPE.OWNER);
		}
		vexaminfolistDTO.set_dynamicWhereCondition(statementDTO.getSQLStatement());
		examListDB=queryDAO.queryForObjectList(VexaminfolistDTO.SQL_SEARCH, vexaminfolistDTO);
		if(examListDB==null || examListDB.size()==0){
			createApplicationException("errMsg", "没找到要查询的信息");
		}else{
			for(VexaminfolistDTO item:examListDB){
				examList.add(convertToVexamListInfo(item));
			}
		}
		return examList.toArray(new VexaminfolistInfoDTO[examList.size()]);
		
	}
	private VexaminfolistInfoDTO convertToVexamListInfo(VexaminfolistDTO item){
		VexaminfolistInfoDTO vexaminfolistInfoDTO = new VexaminfolistInfoDTO();
		vexaminfolistInfoDTO.setexaminationdocid(item.getexaminationdocid());;
		vexaminfolistInfoDTO.setcatagorycname(item.getcatagorycname());
		vexaminfolistInfoDTO.setname(item.getname());
		vexaminfolistInfoDTO.setsenddate(item.getsenddate());
		vexaminfolistInfoDTO.setsendtime(item.getsendtime());
		vexaminfolistInfoDTO.setusername(item.getusername());
		return vexaminfolistInfoDTO;
	}
	@Override
	public void deleteExam(String actionType, String examSql, Integer examId) {

		if(actionType.equals("single")){
			ExaminationdocDTO examDTO =new ExaminationdocDTO();
			if(examId==null){
				return ;
			}
			examDTO.setexaminationdocid(examId);
			updateDAO.updateOne(ExaminationdocDTO.DELETE, examDTO, M10190WS);
		}else if(actionType.equals("many")){
			String[] dbSqlArray=examSql.split(",");
			for (int i = 0; i < dbSqlArray.length; i++) {
				if(StringUtil.isEmpty(dbSqlArray[i])){
					break;
				}
				ExaminationdocDTO examDTO =new ExaminationdocDTO();
				examDTO.setexaminationdocid(Integer.parseInt(dbSqlArray[i]));
				updateDAO.updateOne(ExaminationdocDTO.DELETE, examDTO, M10190WS);
			}
		}
	
	}

	
}
